﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// 数据访问类:SysBasicCodeCls
    /// </summary>
    public partial class SysBasicCodeCls
    {
        public SysBasicCodeCls()
        { }
        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string FCodeClsNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from t_SysBasicCodeCls");
            strSql.Append(" where FCodeClsNo=@FCodeClsNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FCodeClsNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = FCodeClsNo;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(ElingOA6_Admin_DSJCJ.Model.SysBasicCodeCls model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_SysBasicCodeCls(");
            strSql.Append("FCodeClsNo,FParentCodeClsNo,FCodeClsName,FSpecURL,FFiledName)");
            strSql.Append(" values (");
            strSql.Append("@FCodeClsNo,@FParentCodeClsNo,@FCodeClsName,@FSpecURL,@FFiledName)");
            SqlParameter[] parameters = {
					new SqlParameter("@FCodeClsNo", SqlDbType.NVarChar,8),
					new SqlParameter("@FParentCodeClsNo", SqlDbType.NVarChar,8),
					new SqlParameter("@FCodeClsName", SqlDbType.NVarChar,30),
					new SqlParameter("@FSpecURL", SqlDbType.NVarChar,255),
					new SqlParameter("@FFiledName", SqlDbType.NVarChar,30)};
            parameters[0].Value = model.FCodeClsNo;
            parameters[1].Value = model.FParentCodeClsNo;
            parameters[2].Value = model.FCodeClsName;
            parameters[3].Value = model.FSpecURL;
            parameters[4].Value = model.FFiledName;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ElingOA6_Admin_DSJCJ.Model.SysBasicCodeCls model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_SysBasicCodeCls set ");
            strSql.Append("FParentCodeClsNo=@FParentCodeClsNo,");
            strSql.Append("FCodeClsName=@FCodeClsName,");
            strSql.Append("FSpecURL=@FSpecURL,");
            strSql.Append("FFiledName=@FFiledName");
            strSql.Append(" where FCodeClsNo=@FCodeClsNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FParentCodeClsNo", SqlDbType.NVarChar,8),
					new SqlParameter("@FCodeClsName", SqlDbType.NVarChar,30),
					new SqlParameter("@FSpecURL", SqlDbType.NVarChar,255),
					new SqlParameter("@FFiledName", SqlDbType.NVarChar,30),
					new SqlParameter("@FCodeClsNo", SqlDbType.NVarChar,8)};
            parameters[0].Value = model.FParentCodeClsNo;
            parameters[1].Value = model.FCodeClsName;
            parameters[2].Value = model.FSpecURL;
            parameters[3].Value = model.FFiledName;
            parameters[4].Value = model.FCodeClsNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string FCodeClsNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_SysBasicCodeCls ");
            strSql.Append(" where FCodeClsNo=@FCodeClsNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FCodeClsNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = FCodeClsNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string FCodeClsNolist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_SysBasicCodeCls ");
            strSql.Append(" where FCodeClsNo in (" + FCodeClsNolist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.SysBasicCodeCls GetModel(string FCodeClsNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FCodeClsNo,FParentCodeClsNo,FCodeClsName,FSpecURL,FFiledName from t_SysBasicCodeCls ");
            strSql.Append(" where FCodeClsNo=@FCodeClsNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FCodeClsNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = FCodeClsNo;

            ElingOA6_Admin_DSJCJ.Model.SysBasicCodeCls model = new ElingOA6_Admin_DSJCJ.Model.SysBasicCodeCls();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.FCodeClsNo = ds.Tables[0].Rows[0]["FCodeClsNo"].ToString();
                model.FParentCodeClsNo = ds.Tables[0].Rows[0]["FParentCodeClsNo"].ToString();
                model.FCodeClsName = ds.Tables[0].Rows[0]["FCodeClsName"].ToString();
                model.FSpecURL = ds.Tables[0].Rows[0]["FSpecURL"].ToString();
                model.FFiledName = ds.Tables[0].Rows[0]["FFiledName"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FCodeClsNo,FParentCodeClsNo,FCodeClsName,FSpecURL,FFiledName ");
            strSql.Append(" FROM t_SysBasicCodeCls ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" FCodeClsNo,FParentCodeClsNo,FCodeClsName,FSpecURL,FFiledName ");
            strSql.Append(" FROM t_SysBasicCodeCls ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "t_SysBasicCodeCls";
            parameters[1].Value = "FCodeClsNo";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method


        #region 增加的方法

        /// <summary>
        /// 获取编码类型名称
        /// <creator>rend</creator>
        /// <date>2012-11-12</date>
        /// </summary>
        /// <param name="codeClsNo"></param>
        /// <returns></returns>
        public string GetCodeClsName(string codeClsNo)
        {
            string strSql = "select FCodeClsName from t_SysBasicCodeCls where FCodeClsNo=@FCodeClsNo";
            SqlParameter[] parameters = { 
                    new SqlParameter("@FCodeClsNo",SqlDbType.NVarChar,8)};

            parameters[0].Value = codeClsNo;

            object obj = DbHelperSQL.GetSingle(strSql, parameters);
            if (null != obj)
            {
                return obj.ToString();
            }
            else
            {
                return string.Empty;
            }
        }

        #endregion

    }
}
